<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* Mapv (https://github.com/huiyan-fe/mapv)
*********************************************************************-->
<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title data-i18n="resources.title_mapVLayerPolygon"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" include="mapv" src="../../dist/maplibregl/include-maplibregl.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }

        .maplibregl-popup-close-button {
          outline: none;
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map"></div>
<script type="text/javascript">
    var attribution = "<a href='https://www.maplibre.com/about/maps/' target='_blank'>© MapLibre </a>" +
            " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
            " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a> | </span>" +
            "<a href='https://mapv.baidu.com' target='_blank'>© 2018 百度 MapV</a>";
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var tileURL = host + "/iserver/services/map-china/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}";
    var map = new maplibregl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [tileURL],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        },
        center: [113.28, 22.65],
        zoom: 7
    });
    map.addControl(new maplibregl.NavigationControl(), 'top-left');
    map.addControl(new maplibregl.supermap.LogoControl({ link: "https://iclient.supermap.io" }), 'bottom-right');
    map.on('load', function() {
      loadData();
    });

    //示例数据来源为百度MapV的加偏数据，iClient未做纠偏处理
    function loadData() {
        $.get('../data/guang_dong.json', function (geojson) {
            var dataSet1 = mapv.geojson.getDataSet(geojson);
            var citys = {
                '深圳市': 20,
                '广州市': 40,
                '佛山市': 60,
                '江门市': 80,
                '中山市': 100,
            };
            var data1 = dataSet1.get({
                filter: function (item) {
                    if (!citys[item.name]) {
                        return false;
                    }

                    item.count = citys[item.name];
                    return true;
                }
            });
            dataSet1 = new mapv.DataSet(data1);
            var options = {
                gradient: {
                    0: 'yellow',
                    1: 'red'
                },
                globalAlpha: 0.8,
                draw: 'intensity'
            };
            var mapVLayer1 = new maplibregl.supermap.MapvLayer(dataSet1, options);
            map.addLayer(mapVLayer1);

            var data2 = [];
            for (var key in citys) {
                var center = mapv.utilCityCenter.getCenterByCityName(key.replace('市', ''));
                data2.push(
                    {
                        geometry: {
                            type: 'Point',
                            coordinates: [center.lng, center.lat]
                        },
                        text: key
                    }
                );
            }
            var dataSet2 = new mapv.DataSet(data2);
            var textOptions = {
                draw: 'text',
                font: '14px Arial',
                fillStyle: 'blue',
                shadowColor: 'white',
                shadowBlue: 20,
                zIndex: 11,
                shadowBlur: 10
            };
            var mapVLayer2 = new maplibregl.supermap.MapvLayer(dataSet2, textOptions);
            map.addLayer(mapVLayer2);

            setTimeout(function () {
                new maplibregl.Popup({closeOnClick: false})
                    .setLngLat(map.getCenter())
                    .setHTML(resources.text_iClient)
                    .addTo(map);
            }, 1000)
        });
    }

</script>
</body>
</html>
